<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Deliveryman_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
		$this->db= $this->load->database ('db2', TRUE);
	}
	/*
	 * 得到所有送货员
	 */
	public function find_all_deliverymans(){
		$query=$this->db->get('t_deliveryman');
		return $query->result_array();
	}
	/*
	 * 根据ID得到送货员信息
	 */
	public function load($id){
		$query = $this->db->get_where('t_deliveryman',array('id' => $id));
		if ($row = $query->row_array()){
			return $row;
		}
		return array();
	}
	/*
	 * 添加送货员信息
	 */
	public function create($deliveryman){
		$this->db->insert('t_deliveryman', $deliveryman);
		return $this->db->insert_id();
	}
	/*
	 * 更新送货员信息
	 */
	public function update($id,$deliveryman){
		$this->db->where('id', $id);
		$this->db->update('t_deliveryman', $deliveryman);
		return $this->db->affected_rows()>0;
	}
	/*
	 * 删除送货员信息
	 */
	public function delete($id){
		$this->db->where('id', $id);
		$this->db->delete('t_deliveryman');
		return $this->db->affected_rows()>0;
	}
}